<?php
/* SVN FILE: $Id: wage.php 153 2009-08-03 20:40:03Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* ibMarket ACP fee logs page
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 153 $
* @lastrevision $Date: 2009-08-03 20:40:03 +0000 (Mon, 03 Aug 2009) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2009-08-03 20:40:03 +0000 (Mon, 03 Aug 2009) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/modules_admin/logs/wage.php $
*/


if ( ! defined( 'IN_ACP' ) )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
	exit();
}

class admin_ibmarket_logs_wage extends ipsCommand
{
	/**
	 * Skin object
	 *
	 * @access	private
	 * @var		object			Skin templates
	 */
	private $html;
	
	/**
	 * Main class entry point
	 *
	 * @access	public
	 * @param	object		ipsRegistry reference
	 * @return	void		[Outputs to screen]
	 */
	public function doExecute( ipsRegistry $registry )
	{
		$this->request['st'] = max(0,intval($this->request['st']));
		
		$this->html = $this->registry->output->loadTemplate('cp_skin_logs');
		
		$this->registry->getClass('class_localization')->loadLanguageFile( array( 'admin_market', 'admin_logs' ) );
		
		$execute = array(
							'member' => 'wageMemberLogs',
							'group' => 'wageGroupLogs',
						);
		
		if(!isset($execute[$this->request['do']]))
		{
			$this->registry->output->showError(null);
		}
		
		$function = $execute[$this->request['do']];
		$this->$function();
	}
	
	private function wageMemberLogs()
	{
		$this->DB->build(array(
								'select'	=> 'l.*',
								'from'		=> array('market_wages_collected'=>'l'),
								'add_join'	=> array(
														array(
																'select'	=> 'm.members_display_name, m.member_group_id',
																'from'		=> array('members' => 'm'),
																'where'		=> 'l.id_who=m.member_id',
																'type'		=> 'left'
															),
													),
								'calcRows'	=> TRUE,
								'where'		=> "l.how_much != 0 AND l.to_who = 'm'",
								'order'		=> 'l.time_collected DESC',
								'limit'		=> array($this->request['st'],50),
						)	);
		
		$q = $this->DB->execute();
		$total = $this->DB->fetchCalculatedRows();
		
		$logs = array();
		while($log = $this->DB->fetch())
		{
			$logs[] = $log;
		}
		
		$links = $this->registry->output->generatePagination(array(
																	'totalItems'		=> $total,
																	'itemsPerPage'		=> 50,
																	'currentStartValue'	=> $this->request['st'],
																	'baseUrl'			=> $this->settings['base_url']."module=logs&amp;section=wages",
															)	 );
		
		$this->registry->output->html = $this->html->logWageMember($logs, $links);
		
		$this->registry->getClass('output')->html_main .= $this->registry->getClass('output')->global_template->global_frame_wrapper();
		$this->registry->getClass('output')->sendOutput();
	}
	
	private function wageGroupLogs()
	{
		$this->DB->build(array(
								'select'	=> '*',
								'from'		=> 'market_wages_collected',
								'calcRows'	=> TRUE,
								'where'		=> "how_much != 0 AND to_who = 'g'",
								'order'		=> 'time_collected DESC',
								'limit'		=> array($this->request['st'],50),
						)	);
		
		$q = $this->DB->execute();
		$total = $this->DB->fetchCalculatedRows();
		
		$logs = array();
		while($log = $this->DB->fetch())
		{
			$logs[] = $log;
		}
		
		$links = $this->registry->output->generatePagination(array(
																	'totalItems'		=> $total,
																	'itemsPerPage'		=> 50,
																	'currentStartValue'	=> $this->request['st'],
																	'baseUrl'			=> $this->settings['base_url']."module=logs&amp;section=wages",
															)	 );
		
		$this->registry->output->html = $this->html->logWageGroup($logs, $links);
		
		$this->registry->getClass('output')->html_main .= $this->registry->getClass('output')->global_template->global_frame_wrapper();
		$this->registry->getClass('output')->sendOutput();
	}
}